<?php

namespace App\Observers;

use App\Models\Comment;
use App\Models\CommentsLike;

class CommentLikeObserver
{

    /**
     * 监听创建前事件.
     *
     * @param CommentsLike $model
     * @return void
     */
    public function creating(CommentsLike $model)
    {

    }

    /**
     * 监听创建事件.
     *
     * @param CommentsLike $model
     * @return void
     */
    public function created(CommentsLike $model)
    {
        Comment::where('id', $model->comment_id)->increment('like_amount');
    }

    public function updating(CommentsLike $model)
    {

    }

    /**
     * 监听更新后事件.
     *
     * @param CommentsLike $model
     * @return void
     */
    public function updated(CommentsLike $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param CommentsLike $model
     * @return void
     */
    public function deleting(CommentsLike $model)
    {

    }

    /**
     * 监听删除事件.
     *
     * @param CommentsLike $model
     * @return void
     */
    public function deleted(CommentsLike $model)
    {
        Comment::where('id', $model->comment_id)->decrement('like_amount');
    }

}
